package me.keiwu.pub.data;

import lombok.Data;
import org.springframework.data.domain.Sort;

import java.util.List;

/**
 * Created by kei on 22/01/2018.
 */
@Data
public class Page<T> {

    private int page;

    private int size;

    private int offset;

    private int total;

    private int totalPages;

    private List<T> content;

    private Sort sort;


    private Page() {}

    /**
     * page从0开始
     * @param page
     * @param size
     */
    public Page(int page, int size) {
        this.page = page;
        this.size = size;
        this.offset = page * size;
    }

    public void setTotal(int total) {
        this.total = total;
        this.totalPages = (total / size) + ((total % size) > 0 ? 1 : 0);
    }
}
